/**
 * Project Name:九色鹿
 * File Name:VerifySmsAutoConfiguration.java
 * Package Name:com.fxp.project.sms.chuanglan
 * Date:2021年09月13日 17:38
 * Copyright (c) 2021, Jason.Wang All Rights Reserved.
 */
package com.fxp.project.sms.chuanglan.configuration;

import com.fxp.project.sms.chuanglan.config.VerificationProperties;
import com.fxp.project.sms.chuanglan.provider.VerifySmsProvider;
import com.fxp.project.sms.chuanglan.service.ISmsService;
import com.fxp.project.sms.chuanglan.service.impl.VerificationSmsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * ClassName:VerifySmsAutoConfiguration<br/>
 * Function: 创蓝云的自动注入类<br/>
 * Date:2021年09月13日 17:38<br/>
 *
 * @author Jason.Wang
 * @version 1.0.0.0
 * @see
 * @since JDK 8
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "sms.chuanglan.verification", name = "app-id")
@EnableConfigurationProperties({VerificationProperties.class})
@Import({VerifySmsProvider.class})
public class VerifySmsAutoConfiguration {
    /**
     * 定义接口对象
     */
    private final VerifySmsProvider verifySmsProvider;
    @Autowired
    private VerificationProperties verificationProperties;

    /**
     * SmsServiceAutoConfiguration: 构建自动注入对象<br/>
     *
     * @param verifySmsProvider
     * @author Jason.Wang
     * @date 2021/9/13 17:53
     */
    public VerifySmsAutoConfiguration(VerifySmsProvider verifySmsProvider) {
        this.verifySmsProvider = verifySmsProvider;
    }

    /**
     * VerificationSmsServiceImpl: 创建实体对象<br/>
     *
     * @return
     * @author Jason.Wang
     * @date 2021/9/14 11:41
     */
    @Bean(name = "verificationSmsService")
    @ConditionalOnMissingBean(VerificationSmsServiceImpl.class)
    ISmsService VerificationSmsServiceImpl() {
        VerificationSmsServiceImpl.initInstance(verifySmsProvider.init(verificationProperties));
        return VerificationSmsServiceImpl.getInstance();
    }
}